"""捕获异常三种用法
try-except
try-except-finally
try-finally
"""
def read():
    a=10
    b = int(input("输入b:"))

    try:
        c=a/b
        print("结果：",c)
    except ZeroDivisionError as e: #错误类型
        print(e)
        print("除数不能为零")
    finally:
        print("finally关闭资源,无论是否有异常，都会执行")
        
def write():
    #打开文件
    f = open("hhh,txt","w")
    try:
        a=10
        b=2
        rst = a/b
        f.write(rst)
        f.close()
    except Exception as e:
        print("出现异常：",e,type(e))
    finally:
        print("关闭资源")
        
if __name__ == '__main__':
    read()
    write()
